home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blitzblank / sources / bb.spot < prev    next >
Text File  |  1993-09-17  |  11KB  |  464 lines

  1. ;BB.Spot - Blanker-module for BlitzBlank
  2. ;Copyright 1993 by Thomas Boerkel
  3.  
  4. CloseEd
  5. NoCli
  6.  
  7. NEWTYPE.table
  8. r.l
  9. g.l
  10. b.l
  11. End NEWTYPE
  12.  
  13. NEWTYPE.tags
  14. a.l
  15. b
  16. c
  17. d
  18. e
  19. f
  20. End NEWTYPE
  21.  
  22. NEWTYPE.spritedata
  23. a.w
  24. b
  25. c
  26. d
  27. e
  28. f
  29. End NEWTYPE
  30.  
  31. DEFTYPE.Screen *fs,*myscreen,*myscreen2,*myscreen3
  32. DEFTYPE.ViewPort *vp
  33. DEFTYPE.RastPort *rp
  34. DEFTYPE.ColorMap *cm
  35. DEFTYPE.NewScreen newscreen
  36. DEFTYPE.Message *msg
  37. DEFTYPE.table tab
  38. DEFTYPE.MsgPort *port
  39. DEFTYPE.tags tags
  40. DEFTYPE.spritedata *sprdata
  41. DEFTYPE.SimpleSprite spr
  42. DEFTYPE.Window *mywindow
  43. DEFTYPE.NewWindow newwindow
  44. DEFTYPE.l
  45.  
  46. Statement stringborder{x,y,w,h}
  47. Wline x+1,y+h+2,x+1,y,x+w+8,y,1
  48. Wline x+w+10,y-1,x+w+10,y+h+4,x-1,y+h+4,1
  49. Wline x,y+h+3,x,y,1
  50. Wline x+w+11,y-1,x+w+11,y+h+4,1
  51. Wline x-1,y+h+3,x-1,y-1,x+w+10,y-1,2
  52. Wline x+w+9,y,x+w+9,y+h+3,x+1,y+h+3,2
  53. Wline x-2,y+h+4,x-2,y-1,2
  54. Wline x+w+8,y+1,x+w+8,y+h+2,2
  55. End Statement
  56.  
  57.  
  58. Select Par$(1)
  59.   Case "BLANK"
  60.     ;Delay_ 100
  61.     name$="BB.BlankModule"+Chr$(0)
  62.     *port=CreateMsgPort_()
  63.     *port\mp_Node\ln_Name=&name$
  64.     *port\mp_Node\ln_Pri=1
  65.     AddPort_ *port
  66.     SetTaskPri_ FindTask_(0),Val(Par$(8))
  67.     *sprdata=AllocMem_(SizeOf.spritedata,#MEMF_CHIP|#MEMF_CLEAR)
  68.     newwindow\LeftEdge=0,0,1,1
  69.     newwindow\Flags=#WFLG_ACTIVATE
  70.     newwindow\FirstGadget=0,0,0,0,0,-1,-1,-1,-1,#WBENCHSCREEN
  71.  
  72.     *mywindow=OpenWindow_(newwindow)
  73.  
  74.     VWait
  75.     SetPointer_ *mywindow,*sprdata,0,0,0,0
  76.  
  77.     Gosub readconfig
  78.     If s=3 Then s=4
  79.     lib$="intuition.library"+Chr$(0)
  80.     *ibase.IntuitionBase=OpenLibrary_(&lib$,39)
  81.     CloseLibrary_ *ibase
  82.  
  83.     If *ibase
  84.       v39=1
  85.     Else
  86.       *ibase.IntuitionBase=OpenLibrary_(&lib$,37)
  87.       CloseLibrary_ *ibase
  88.     EndIf
  89.  
  90.     *fs=*ibase\FirstScreen
  91.  
  92.  
  93.     left=*fs\LeftEdge
  94.     top=*fs\TopEdge
  95.     width=*fs\Width
  96.     height=*fs\Height
  97.     modeid=GetVPModeID_(*fs\ViewPort)
  98.  
  99.     depth=*fs\BitMap\Depth
  100.     *cm=*fs\ViewPort\ColorMap
  101.     title$="BB.Spot0"+Chr$(0)
  102.     newscreen\LeftEdge=left,top,width,height,depth+1
  103.     newscreen\ViewModes=0,#CUSTOMSCREEN|#SCREENBEHIND,0,&title$
  104.     tags\a=#SA_DisplayID
  105.     tags\b=modeid
  106.     tags\c=0
  107.     *myscreen=OpenScreenTagList_(newscreen,tags)
  108.     If spots>1
  109.       title2$="BB.Spot1"+Chr$(0)
  110.       newscreen\ViewModes=0,#CUSTOMSCREEN|#SCREENBEHIND,0,&title2$
  111.       *myscreen2=OpenScreenTagList_(newscreen,tags)
  112.     EndIf
  113.     If *myscreen=0 OR (spots>1 AND *myscreen2=0)
  114.       newscreen\LeftEdge=0,0,width,height,1,1,2
  115.       newscreen\Type=#CUSTOMSCREEN
  116.       *myscreen=OpenScreenTagList_(newscreen,tags)
  117.       If *myscreen
  118.         VWait
  119.         ChangeSprite_ 0,spr,*sprdata
  120.         SetRGB4_ *myscreen\ViewPort,0,0,0,0
  121.         WaitPort_ *port
  122.         *msg=GetMsg_(*port)
  123.         CloseScreen_ *myscreen
  124.       EndIf
  125.     Else
  126.       gy=gx*height/width*1.15
  127.       cmax=2^depth
  128.       title3$="BB.Spot2"+Chr$(0)
  129.       newscreen\LeftEdge=0,0,gx+4*s,gy+4*s,depth+1
  130.       newscreen\ViewModes=0,#CUSTOMSCREEN|#SCREENBEHIND,0,&title3$
  131.       *myscreen3=OpenScreenTagList_(newscreen,tags)
  132.       *rp3.RastPort=*myscreen3\RastPort
  133.       *buf=AllocMem_((gx+4*s)*(gy+4*s)/8+100,#MEMF_CHIP|#MEMF_CLEAR)
  134.       InitTmpRas_ tmpras.TmpRas,*buf,(gx+4*s)*(gy+4*s)/8+100
  135.       buf$=String$(" ",50)
  136.       *ai.AreaInfo=AllocMem_(SizeOf.AreaInfo,#MEMF_CLEAR)
  137.       InitArea_ *ai.AreaInfo,&buf$,3
  138.       *rp3\TmpRas=tmpras
  139.       *rp3\AreaInfo=*ai
  140.       SetAPen_ *rp3,cmax
  141.       AreaEllipse_ *rp3,gx/2+s*2,gy/2+s*2,gx/2,gy/2
  142.       AreaEnd_ *rp3
  143.       FreeMem_ *ai,SizeOf.AreaInfo
  144.       FreeMem_ *buf,(gx+4*s)*(gy+4*s)/8+100
  145.       b2=*myscreen3\BitMap
  146.       Dim b1(2)
  147.       b0=*fs\BitMap
  148.       b1(0)=*myscreen\BitMap
  149.       FindScreen 0,"BB.Spot0"
  150.       If spots>1
  151.         b1(1)=*myscreen2\BitMap
  152.         *vp2=*myscreen2\ViewPort
  153.         FindScreen 1,"BB.Spot1"
  154.       EndIf
  155.  
  156.  
  157.       gx=gx+4*s
  158.       gy=gy+4*s
  159.       *vp=*myscreen\ViewPort
  160.       *rp=*myscreen\RastPort
  161.       BltBitMap_ b0,0,0,b1(0),0,0,width,height,$C0,2^depth-1,0
  162.       If spots>1 Then BltBitMap_ b0,0,0,b1(1),0,0,width,height,$C0,2^depth-1,0
  163.       USEPATH tab
  164.       For i=0 To cmax-1
  165.         If v39
  166.           GetRGB32_ *cm,i,1,tab
  167.           SetRGB32_ *vp,cmax+i,tab\r,tab\g,tab\b
  168.           If spots>1 Then SetRGB32_ *vp2,cmax+i,tab\r,tab\g,tab\b
  169.           \r=(\r AND 255)*fade/100
  170.           \g=(\g AND 255)*fade/100
  171.           \b=(\b AND 255)*fade/100
  172.           \r|\r LSL 8|\r LSL 16|\r LSL 24
  173.           \g|\g LSL 8|\g LSL 16|\g LSL 24
  174.           \b|\b LSL 8|\b LSL 16|\b LSL 24
  175.           SetRGB32_ *vp,i,\r,\g,\b
  176.           If spots>1 Then SetRGB32_ *vp2,i,\r,\g,\b
  177.         Else
  178.           c=GetRGB4_(*cm,i)
  179.           r=(c LSR 8) AND 15
  180.           g=(c LSR 4) AND 15
  181.           b=c AND 15
  182.           SetRGB4_ *vp,cmax+i,r,g,b
  183.           If spots>1 Then SetRGB4_ *vp2,cmax+i,r,g,b
  184.           r*fade/100
  185.           g*fade/100
  186.           b*fade/100
  187.           SetRGB4_ *vp,i,r,g,b
  188.           If spots>1 Then SetRGB4_ *vp2,i,r,g,b
  189.         EndIf
  190.       Next i
  191.       ScreenToFront_ *myscreen
  192.       Dim x.q(spots+1)
  193.       Dim y.q(spots+1)
  194.       Dim dx.q(spots+1)
  195.       Dim dy.q(spots+1)
  196.       For i=1 To spots
  197.         x(i)=width/2-gx/2
  198.         y(i)=height/2-gy/2
  199.         fdummy.q=Rnd(2*s*10)/10
  200.         dx(i)=fdummy-s
  201.         fdummy=Rnd(2*s*10)/10
  202.         dy(i)=fdummy-s
  203.       Next i
  204.  
  205.       Repeat
  206.         If spots=1
  207.           VWait
  208.         EndIf
  209.         If spots>1
  210.           For i=1 To spots
  211.             BltBitMap_ b2,0,0,b1(sc),Int(x(i)),Int(y(i)),gx,gy,$00,cmax,0
  212.           Next i
  213.         EndIf
  214.         For i=1 To spots
  215.           If Int(Rnd(20/s))=0
  216.             Gosub newd
  217.           EndIf
  218.           If y(i)+dy(i)<0 OR y(i)+dy(i)+gy>height-1
  219.             dy(i)=-dy(i)
  220.           EndIf
  221.  
  222.           If x(i)+dx(i)<0 OR x(i)+dx(i)+gx>width-1
  223.             dx(i)=-dx(i)
  224.           EndIf
  225.           x(i)+dx(i)
  226.           y(i)+dy(i)
  227.           pos=y(i)+gy/2+100
  228.  
  229.           If spots=1 AND smooth=2 AND y(i)<gy
  230.             Repeat
  231.             Until VBeamPos_()>pos
  232.          EndIf
  233.           If update
  234.             BltBitMap_ b0,Int(x(i)),Int(y(i)),b1(sc),Int(x(i)),Int(y(i)),gx,gy,$C0,$FF,0
  235.           EndIf
  236.           If spots>1
  237.             BltBitMap_ b2,0,0,b1(sc),Int(x(i)),Int(y(i)),gx,gy,$E0,cmax,0
  238.           Else
  239.             BltBitMap_ b2,0,0,b1(sc),Int(x(i)),Int(y(i)),gx,gy,$C0,cmax,0
  240.           EndIf
  241.         Next i
  242.         If spots>1
  243.           ShowScreen sc
  244.           sc=1-sc
  245.         EndIf
  246.         *msg=GetMsg_(*port)
  247.       Until *msg
  248.       CloseScreen_ *myscreen3
  249.       CloseScreen_ *myscreen2
  250.       CloseScreen_ *myscreen
  251.     EndIf
  252.     ClearPointer_ *mywindow
  253.     CloseWindow_ *mywindow
  254.     FreeMem_ *sprdata,SizeOf.spritedata
  255.     RemPort_ *port
  256.     DeleteMsgPort_ *port
  257.  
  258.   Case "INFO"
  259.     title$="Spot"+Chr$(0)
  260.     reqtext$="Spot - Module for BlitzBlank"+Chr$(10)
  261.     reqtext$+Chr$(169)+" 1993 by Thomas Brkel"+Chr$(10)+Chr$(10)
  262.     reqtext$+"Spotlights move over your actual screen."+Chr$(10)+Chr$(10)
  263.     reqtext$+"Choose speed, size, number, fading, update, smoothing"+Chr$(10)
  264.     reqtext$+"in the config-window."+Chr$(0)
  265.     gadget$="OK"+Chr$(0)
  266.     easy.EasyStruct\es_StructSize=SizeOf.EasyStruct
  267.     easy\es_Title=&title$
  268.     easy\es_TextFormat=&reqtext$
  269.     easy\es_GadgetFormat=&gadget$
  270.     EasyRequestArgs_ 0,easy,0,0
  271.   Case "CONFIG"
  272.     *myscreen=LockPubScreen_(0)
  273.     width=*myscreen\Width
  274.     height=*myscreen\Height
  275.     font=*myscreen\Font\ta_YSize
  276.     Gosub readconfig
  277.     WbToScreen 0
  278.     BorderPens 0,0
  279.     StringGadget 0,180,25,0,4,5,40
  280.     StringGadget 0,180,50,0,5,5,40
  281.     StringGadget 0,180,75,0,6,5,40
  282.     SetString 0,4,Str$(gx)
  283.     SetString 0,5,Str$(spots)
  284.     SetString 0,6,Str$(fade)
  285.  
  286.     BorderPens 2,1
  287.     TextGadget 0,20,105,1,3," Update "
  288.     TextGadget 0,20,135,1,7," Smooth "
  289.     ButtonGroup 1
  290.     TextGadget 0,20,25,512,0,"  Slow  "
  291.     TextGadget 0,20,50,512,1," Normal "
  292.     TextGadget 0,20,75,512,2,"  Fast  "
  293.     Toggle 0,s-1,On
  294.     If update
  295.       Toggle 0,3,On
  296.     EndIf
  297.     If smooth=2
  298.       Toggle 0,7,On
  299.     EndIf
  300.     Window 0,width/2-125,height/2-80,250,160,$100e,"Spot",1,2,0
  301.     stringborder{180,25,40,8}
  302.     stringborder{180,50,40,8}
  303.     stringborder{180,75,40,8}
  304.     WColour 2
  305.     WLocate 105,24-font
  306.     Print "Size:"
  307.     WLocate 105,24-font+8
  308.     Print "(10-150)"
  309.     WLocate 105,49-font
  310.     Print "Number:"
  311.     WLocate 105,49-font+8
  312.     Print "(1-100)"
  313.     WLocate 105,74-font
  314.     Print "Fade to:"
  315.     WLocate 105,74-font+8
  316.     Print "(0-99)"
  317.     ActivateString 0,4
  318.     If update=1
  319.       Disable 0,6
  320.       Redraw 0,6
  321.       stringborder{180,75,40,8}
  322.     EndIf
  323.     Repeat
  324.       ev=WaitEvent
  325.       If ev=$40
  326.         Select GadgetHit
  327.           Case 3
  328.             If GadgetStatus(0,3)
  329.               update=1
  330.               Disable 0,6
  331.               Redraw 0,6
  332.               stringborder{180,75,40,8}
  333.             Else
  334.               update=0
  335.               Enable 0,6
  336.               Redraw 0,6
  337.               stringborder{180,75,40,8}
  338.             EndIf
  339.           Case 4
  340.             ActivateString 0,5
  341.           Case 5
  342.             If update=0
  343.               ActivateString 0,6
  344.             Else
  345.               e=1
  346.             EndIf
  347.           Case 6
  348.             e=1
  349.         End Select
  350.       EndIf
  351.     Until ev=$200 OR e
  352.  
  353.     s=ButtonId(0,1)+1
  354.     If GadgetStatus(0,7)
  355.       smooth=2
  356.     Else
  357.       smooth=1
  358.     EndIf
  359.     gx=Val(StringText$(0,4))
  360.     spots=Val(StringText$(0,5))
  361.     If update=0
  362.       fade=Val(StringText$(0,6))
  363.     Else
  364.       fade=0
  365.     EndIf
  366.     Free Window 0
  367.     Gosub writeconfig
  368.     UnlockPubScreen_ 0,*myscreen
  369. End Select
  370.  
  371. End
  372.  
  373. .readconfig
  374. path$=Par$(9)
  375. For i=10 To NumPars
  376.   path$=path$+" "+Par$(i)
  377. Next i
  378. If ReadFile(0,path$+"BB.Modules.config")
  379.   FileInput 0
  380.   While NOT Eof(0)
  381.     If Edit$(100)="*** Spot ***"
  382.       s=Val(Edit$(5))
  383.       update=Val(Edit$(5))
  384.       gx=Val(Edit$(5))
  385.       spots=Val(Edit$(5))
  386.       fade=Val(Edit$(5))
  387.       smooth=Val(Edit$(5))
  388.     EndIf
  389.   Wend
  390.   DefaultInput
  391.   CloseFile 0
  392. EndIf
  393. Gosub checkval
  394. Return
  395.  
  396.  
  397. .writeconfig
  398. Gosub checkval
  399. If ReadFile(0,path$+"BB.Modules.config")
  400.   If WriteFile(1,path$+"BB.Modules.temp")
  401.     FileInput 0
  402.     FileOutput 1
  403.     While NOT Eof(0)
  404.       f$=Edit$(100)
  405.       If f$="*** Spot ***"
  406.         Repeat
  407.           f2$=Edit$(100)
  408.         Until Eof(0) OR Left$(f2$,3)="***"
  409.         If NOT Eof(0) Then NPrint f2$
  410.       Else
  411.         NPrint f$
  412.       EndIf
  413.     Wend
  414.     CloseFile 1
  415.   EndIf
  416.   CloseFile 0
  417. EndIf
  418. KillFile path$+"BB.Modules.config"
  419. f$=path$+"BB.Modules.temp"+Chr$(0)
  420. f2$=path$+"BB.Modules.config"+Chr$(0)
  421. Rename_ &f$,&f2$
  422. If OpenFile(0,path$+"BB.Modules.config")
  423.   FileOutput 0
  424.   FileSeek 0,Lof(0)
  425.   NPrint "*** Spot ***"
  426.   NPrint s
  427.   NPrint update
  428.   NPrint gx
  429.   NPrint spots
  430.   NPrint fade
  431.   NPrint smooth
  432.   CloseFile 0
  433. EndIf
  434. Return
  435.  
  436. .checkval
  437. If s<1 Then s=1
  438. If s>3 Then s=3
  439. If update<0 Then update=0
  440. If update>1 Then update=1
  441. If spots<1 Then spots=1
  442. If spots>100 Then spots=100
  443. If gx<10 Then gx=100
  444. If gx>150 Then gx=100
  445. If fade<0 Then fade=0
  446. If fade>99 Then fade=99
  447. If smooth<1 Then smooth=1
  448. If smooth>2 Then smooth=1
  449. Return
  450.  
  451. .newd
  452. ddx.q=(Int(Rnd(3))-1)/4
  453. ddy.q=(Int(Rnd(3))-1)/4
  454. If NOT((dx(i)+ddx<>0 OR dy(i)+ddy<>0) AND Abs(dx(i)+ddx)<=s AND Abs(dx(i)+ddx)>=s/3)
  455.   ddx=-ddx
  456. EndIf
  457. If NOT((dx(i)+ddx<>0 OR dy(i)+ddy<>0) AND Abs(dy(i)+ddy)<=s AND Abs(dy(i)+ddy)>=s/3)
  458.   ddy=-ddy
  459. EndIf
  460. dx(i)+ddx
  461. dy(i)+ddy
  462. Return
  463.  
  464.